
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Visual Dom · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="create-element.html" />
    
    
    <link rel="prev" href="render.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../prepare/">
            
                <a href="../prepare/">
            
                    
                    准备工作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../prepare/flow.html">
            
                <a href="../prepare/flow.html">
            
                    
                    认识flow
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../prepare/directory.html">
            
                <a href="../prepare/directory.html">
            
                    
                    Vue.js源码目录设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../prepare/build.html">
            
                <a href="../prepare/build.html">
            
                    
                    Vue.js源码构建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../prepare/entrance.html">
            
                <a href="../prepare/entrance.html">
            
                    
                    从入口开始
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    数据驱动
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="./">
            
                <a href="./">
            
                    
                    数据驱动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="new-vue.html">
            
                <a href="new-vue.html">
            
                    
                    new Vue发生了什么
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="mounted.html">
            
                <a href="mounted.html">
            
                    
                    Vue实例挂载的实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="render.html">
            
                <a href="render.html">
            
                    
                    render
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.5" data-path="virtual-dom.html">
            
                <a href="virtual-dom.html">
            
                    
                    Visual Dom
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="create-element.html">
            
                <a href="create-element.html">
            
                    
                    createElement
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="update.html">
            
                <a href="update.html">
            
                    
                    update
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Visual Dom</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="virtual-dom">Virtual DOM</h1>
<p>Virtual DOM &#x8FD9;&#x4E2A;&#x6982;&#x5FF5;&#x76F8;&#x4FE1;&#x5927;&#x90E8;&#x5206;&#x4EBA;&#x90FD;&#x4E0D;&#x4F1A;&#x964C;&#x751F;&#xFF0C;&#x5B83;&#x4EA7;&#x751F;&#x7684;&#x524D;&#x63D0;&#x662F;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x7684; DOM &#x662F;&#x5F88;&#x201C;&#x6602;&#x8D35;&quot;&#x7684;&#xFF0C;&#x4E3A;&#x4E86;&#x66F4;&#x76F4;&#x89C2;&#x7684;&#x611F;&#x53D7;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7B80;&#x5355;&#x7684;&#x628A;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684; div &#x5143;&#x7D20;&#x7684;&#x5C5E;&#x6027;&#x90FD;&#x6253;&#x5370;&#x51FA;&#x6765;&#xFF0C;&#x5982;&#x56FE;&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="dom.png" alt="dom&#x5C5E;&#x6027;"></p>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x771F;&#x6B63;&#x7684; DOM &#x5143;&#x7D20;&#x662F;&#x975E;&#x5E38;&#x5E9E;&#x5927;&#x7684;&#xFF0C;&#x56E0;&#x4E3A;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x6807;&#x51C6;&#x5C31;&#x628A; DOM &#x8BBE;&#x8BA1;&#x7684;&#x975E;&#x5E38;&#x590D;&#x6742;&#x3002;&#x5F53;&#x6211;&#x4EEC;&#x9891;&#x7E41;&#x7684;&#x53BB;&#x505A; DOM &#x66F4;&#x65B0;&#xFF0C;&#x4F1A;&#x4EA7;&#x751F;&#x4E00;&#x5B9A;&#x7684;&#x6027;&#x80FD;&#x95EE;&#x9898;&#x3002;</p>
<p>&#x800C; Virtual DOM &#x5C31;&#x662F;&#x7528;&#x4E00;&#x4E2A;&#x539F;&#x751F;&#x7684; JS &#x5BF9;&#x8C61;&#x53BB;&#x63CF;&#x8FF0;&#x4E00;&#x4E2A; DOM &#x8282;&#x70B9;&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x6BD4;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; DOM &#x7684;&#x4EE3;&#x4EF7;&#x8981;&#x5C0F;&#x5F88;&#x591A;&#x3002;&#x5728; Vue.js &#x4E2D;&#xFF0C;Virtual DOM &#x662F;&#x7528; <code>VNode</code> &#x8FD9;&#x4E48;&#x4E00;&#x4E2A; Class &#x53BB;&#x63CF;&#x8FF0;&#xFF0C;&#x5B83;&#x662F;&#x5B9A;&#x4E49;&#x5728; <code>src/core/vdom/vnode.js</code> &#x4E2D;&#x7684;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">VNode</span> </span>{
  tag: string | <span class="hljs-keyword">void</span>;
  data: VNodeData | <span class="hljs-keyword">void</span>;
  children: ?<span class="hljs-built_in">Array</span>&lt;VNode&gt;;
  text: string | <span class="hljs-keyword">void</span>;
  elm: Node | <span class="hljs-keyword">void</span>;
  ns: string | <span class="hljs-keyword">void</span>;
  context: Component | <span class="hljs-keyword">void</span>; <span class="hljs-comment">// rendered in this component&apos;s scope</span>
  key: string | number | <span class="hljs-keyword">void</span>;
  componentOptions: VNodeComponentOptions | <span class="hljs-keyword">void</span>;
  componentInstance: Component | <span class="hljs-keyword">void</span>; <span class="hljs-comment">// component instance</span>
  parent: VNode | <span class="hljs-keyword">void</span>; <span class="hljs-comment">// component placeholder node</span>

  <span class="hljs-comment">// strictly internal</span>
  raw: boolean; <span class="hljs-comment">// contains raw HTML? (server only)</span>
  isStatic: boolean; <span class="hljs-comment">// hoisted static node</span>
  isRootInsert: boolean; <span class="hljs-comment">// necessary for enter transition check</span>
  isComment: boolean; <span class="hljs-comment">// empty comment placeholder?</span>
  isCloned: boolean; <span class="hljs-comment">// is a cloned node?</span>
  isOnce: boolean; <span class="hljs-comment">// is a v-once node?</span>
  asyncFactory: <span class="hljs-built_in">Function</span> | <span class="hljs-keyword">void</span>; <span class="hljs-comment">// async component factory function</span>
  asyncMeta: <span class="hljs-built_in">Object</span> | <span class="hljs-keyword">void</span>;
  isAsyncPlaceholder: boolean;
  ssrContext: <span class="hljs-built_in">Object</span> | <span class="hljs-keyword">void</span>;
  fnContext: Component | <span class="hljs-keyword">void</span>; <span class="hljs-comment">// real context vm for functional nodes</span>
  fnOptions: ?ComponentOptions; <span class="hljs-comment">// for SSR caching</span>
  fnScopeId: ?string; <span class="hljs-comment">// functional scope id support</span>

  <span class="hljs-keyword">constructor</span> (
    tag?: string,
    data?: VNodeData,
    children?: ?Array&lt;VNode&gt;,
    text?: string,
    elm?: Node,
    context?: Component,
    componentOptions?: VNodeComponentOptions,
    asyncFactory?: Function
  ) {
    <span class="hljs-keyword">this</span>.tag = tag
    <span class="hljs-keyword">this</span>.data = data
    <span class="hljs-keyword">this</span>.children = children
    <span class="hljs-keyword">this</span>.text = text
    <span class="hljs-keyword">this</span>.elm = elm
    <span class="hljs-keyword">this</span>.ns = <span class="hljs-literal">undefined</span>
    <span class="hljs-keyword">this</span>.context = context
    <span class="hljs-keyword">this</span>.fnContext = <span class="hljs-literal">undefined</span>
    <span class="hljs-keyword">this</span>.fnOptions = <span class="hljs-literal">undefined</span>
    <span class="hljs-keyword">this</span>.fnScopeId = <span class="hljs-literal">undefined</span>
    <span class="hljs-keyword">this</span>.key = data &amp;&amp; data.key
    <span class="hljs-keyword">this</span>.componentOptions = componentOptions
    <span class="hljs-keyword">this</span>.componentInstance = <span class="hljs-literal">undefined</span>
    <span class="hljs-keyword">this</span>.parent = <span class="hljs-literal">undefined</span>
    <span class="hljs-keyword">this</span>.raw = <span class="hljs-literal">false</span>
    <span class="hljs-keyword">this</span>.isStatic = <span class="hljs-literal">false</span>
    <span class="hljs-keyword">this</span>.isRootInsert = <span class="hljs-literal">true</span>
    <span class="hljs-keyword">this</span>.isComment = <span class="hljs-literal">false</span>
    <span class="hljs-keyword">this</span>.isCloned = <span class="hljs-literal">false</span>
    <span class="hljs-keyword">this</span>.isOnce = <span class="hljs-literal">false</span>
    <span class="hljs-keyword">this</span>.asyncFactory = asyncFactory
    <span class="hljs-keyword">this</span>.asyncMeta = <span class="hljs-literal">undefined</span>
    <span class="hljs-keyword">this</span>.isAsyncPlaceholder = <span class="hljs-literal">false</span>
  }

  <span class="hljs-comment">// DEPRECATED: alias for componentInstance for backwards compat.</span>
  <span class="hljs-comment">/* istanbul ignore next */</span>
  get child (): Component | <span class="hljs-keyword">void</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.componentInstance
  }
}
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230; Vue.js &#x4E2D;&#x7684; Virtual DOM &#x7684;&#x5B9A;&#x4E49;&#x8FD8;&#x662F;&#x7565;&#x5FAE;&#x590D;&#x6742;&#x4E00;&#x4E9B;&#x7684;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x8FD9;&#x91CC;&#x5305;&#x542B;&#x4E86;&#x5F88;&#x591A; Vue.js &#x7684;&#x7279;&#x6027;&#x3002;&#x8FD9;&#x91CC;&#x5343;&#x4E07;&#x4E0D;&#x8981;&#x88AB;&#x8FD9;&#x4E9B;&#x832B;&#x832B;&#x591A;&#x7684;&#x5C5E;&#x6027;&#x5413;&#x5230;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A; Vue.js &#x4E2D; Virtual DOM &#x662F;&#x501F;&#x9274;&#x4E86;&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x5E93; <a href="https://github.com/snabbdom/snabbdom" target="_blank">snabbdom</a> &#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x7136;&#x540E;&#x52A0;&#x5165;&#x4E86;&#x4E00;&#x4E9B; Vue.js &#x7279;&#x8272;&#x7684;&#x4E1C;&#x897F;&#x3002;&#x6211;&#x5EFA;&#x8BAE;&#x5927;&#x5BB6;&#x5982;&#x679C;&#x60F3;&#x6DF1;&#x5165;&#x4E86;&#x89E3; Vue.js &#x7684; Virtual DOM &#x524D;&#x4E0D;&#x59A8;&#x5148;&#x9605;&#x8BFB;&#x8FD9;&#x4E2A;&#x5E93;&#x7684;&#x6E90;&#x7801;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x66F4;&#x52A0;&#x7B80;&#x5355;&#x548C;&#x7EAF;&#x7CB9;&#x3002;</p>
<h2 id="&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</h2>
<p>&#x5176;&#x5B9E; VNode &#x662F;&#x5BF9;&#x771F;&#x5B9E; DOM &#x7684;&#x4E00;&#x79CD;&#x62BD;&#x8C61;&#x63CF;&#x8FF0;&#xFF0C;&#x5B83;&#x7684;&#x6838;&#x5FC3;&#x5B9A;&#x4E49;&#x65E0;&#x975E;&#x5C31;&#x51E0;&#x4E2A;&#x5173;&#x952E;&#x5C5E;&#x6027;&#xFF0C;&#x6807;&#x7B7E;&#x540D;&#x3001;&#x6570;&#x636E;&#x3001;&#x5B50;&#x8282;&#x70B9;&#x3001;&#x952E;&#x503C;&#x7B49;&#xFF0C;&#x5176;&#x5B83;&#x5C5E;&#x6027;&#x90FD;&#x662F;&#x7528;&#x6765;&#x6269;&#x5C55; VNode &#x7684;&#x7075;&#x6D3B;&#x6027;&#x4EE5;&#x53CA;&#x5B9E;&#x73B0;&#x4E00;&#x4E9B;&#x7279;&#x6B8A; feature &#x7684;&#x3002;&#x7531;&#x4E8E; VNode &#x53EA;&#x662F;&#x7528;&#x6765;&#x6620;&#x5C04;&#x5230;&#x771F;&#x5B9E; DOM &#x7684;&#x6E32;&#x67D3;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x5305;&#x542B;&#x64CD;&#x4F5C; DOM &#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x56E0;&#x6B64;&#x5B83;&#x662F;&#x975E;&#x5E38;&#x8F7B;&#x91CF;&#x548C;&#x7B80;&#x5355;&#x7684;&#x3002;</p>
<p>Virtual DOM &#x9664;&#x4E86;&#x5B83;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x7684;&#x5B9A;&#x4E49;&#xFF0C;&#x6620;&#x5C04;&#x5230;&#x771F;&#x5B9E;&#x7684; DOM &#x5B9E;&#x9645;&#x4E0A;&#x8981;&#x7ECF;&#x5386; VNode &#x7684; create&#x3001;diff&#x3001;patch &#x7B49;&#x8FC7;&#x7A0B;&#x3002;&#x90A3;&#x4E48;&#x5728; Vue.js &#x4E2D;&#xFF0C;VNode &#x7684; create &#x662F;&#x901A;&#x8FC7;&#x4E4B;&#x524D;&#x63D0;&#x5230;&#x7684; <code>createElement</code> &#x65B9;&#x6CD5;&#x521B;&#x5EFA;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x63A5;&#x4E0B;&#x6765;&#x5206;&#x6790;&#x8FD9;&#x90E8;&#x5206;&#x7684;&#x5B9E;&#x73B0;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="render.html" class="navigation navigation-prev " aria-label="Previous page: render">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="create-element.html" class="navigation navigation-next " aria-label="Next page: createElement">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Visual Dom","level":"1.3.5","depth":2,"next":{"title":"createElement","level":"1.3.6","depth":2,"path":"v2/data-driven/create-element.md","ref":"v2/data-driven/create-element.md","articles":[]},"previous":{"title":"render","level":"1.3.4","depth":2,"path":"v2/data-driven/render.md","ref":"v2/data-driven/render.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"v2/data-driven/virtual-dom.md","mtime":"2021-02-02T01:32:32.298Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-02-02T01:41:31.061Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

